package cn.xfdzx.android.apps.shop.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.FamilyBuyBeen;

public class HomeMarketFamilyTypeAdapter extends BaseMultiItemQuickAdapter<FamilyBuyBeen.DataBean.FamilyShoppingActivityBean, BaseViewHolder> {
    RoundedCorners roundedCorners;
    RequestOptions options;

    public HomeMarketFamilyTypeAdapter(List< FamilyBuyBeen.DataBean.FamilyShoppingActivityBean >list) {
        super(list);
        roundedCorners = new RoundedCorners(8);
        options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);

        addItemType(FamilyBuyBeen.DataBean.FamilyShoppingActivityBean.TYPEFOOT, R.layout.adapter_foot_family_view);
        addItemType(FamilyBuyBeen.DataBean.FamilyShoppingActivityBean.TYPEOTHER, R.layout.adapter_maarket_home_family);

    }


    @Override
    protected void convert(BaseViewHolder helper, FamilyBuyBeen.DataBean.FamilyShoppingActivityBean item) {



        switch (helper.getItemViewType()){
            case  FamilyBuyBeen.DataBean.FamilyShoppingActivityBean.TYPEFOOT:

                break;

            case  FamilyBuyBeen.DataBean.FamilyShoppingActivityBean.TYPEOTHER:
                Glide.with(mContext).load(item.getThumb()).apply(options.transform(new CenterCrop(), roundedCorners)).into((ImageView) helper.getView(R.id.iv_image));

                helper.setText(R.id.tv_home_name, item.getTitle())
                        .setText(R.id.tv_new_price, "¥" + item.getDiscountprice())
                        .setText(R.id.tv_old_price, "¥" + item.getMarketprice());

                TextView oldPrice = helper.getView(R.id.tv_old_price);
                oldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

                TextView tvCarNum = helper.getView(R.id.tv_car_num);
                tvCarNum.setText(item.getCart_num() + "");
                if (item.getCart_num() == 0) {
                    tvCarNum.setVisibility(View.GONE);
                } else {
                    tvCarNum.setVisibility(View.VISIBLE);
                }

                helper.addOnClickListener(R.id.iv_add_car);
                break;
        }
    }
}
